﻿using System;

class HexToBinDirectly
{
    static void Main()
    {
        string hexNum = "FF";
        long binNum = ConvertHexToBinDirectly(hexNum);

        Console.WriteLine("Hexadecimal: " + hexNum);
        Console.WriteLine("Binary:      " + binNum);
    }

    private static long ConvertHexToBinDirectly(string hexNum)
    {
        string binNum = String.Empty;

        for (int i = 0; i < hexNum.Length; i++)
        {
            string hexDigit = hexNum[i].ToString();
            binNum += GetBitsFromHex(hexDigit);
        }

        return long.Parse(binNum);
    }

    private static string GetBitsFromHex(string hexDigit)
    {
        string bitsFromHex = String.Empty;

        switch (hexDigit)
        {
            case "0":
                bitsFromHex = "0000";
                break;
            case "1":
                bitsFromHex = "0001";
                break;
            case "2":
                bitsFromHex = "0010";
                break;
            case "3":
                bitsFromHex = "0011";
                break;
            case "4":
                bitsFromHex = "0100";
                break;
            case "5":
                bitsFromHex = "0101";
                break;
            case "6":
                bitsFromHex = "0110";
                break;
            case "7":
                bitsFromHex = "0111";
                break;
            case "8":
                bitsFromHex = "1000";
                break;
            case "9":
                bitsFromHex = "1001";
                break;
            case "A":
                bitsFromHex = "1010";
                break;
            case "B":
                bitsFromHex = "1011";
                break;
            case "C":
                bitsFromHex = "1100";
                break;
            case "D":
                bitsFromHex = "1101";
                break;
            case "E":
                bitsFromHex = "1110";
                break;
            case "F":
                bitsFromHex = "1111";
                break;
        }

        return bitsFromHex;
    }
}
